<?php
require_once('Kbs/Controller/Action.php');

class Admin_CategoryController extends Kbs_Controller_Action
{
    public function indexAction()
    {
        $this->_forward('list');
    }

    public function listAction()
    {
        $bisObj = new Kbs_Model_Business_Post_Category();
        $this->view->categories = $bisObj->fetchAll();

        $bisObj = new Kbs_Model_Business_Locale();
        $this->view->locales = $bisObj->fetchAll();
    }

    public function saveAction()
    {
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost();

            $category = new Kbs_Model_Business_Post_Category();
            $category->saveCategoryAndDetails($data);

            $this->_redirect('/admin/category');
        } else {
            $this->_redirect('/admin');
        }
    }

    public function deleteAction()
    {
        if ($this->getRequest()->isGet()) {
            $id = $this->_getParam('id');

            $category = new Kbs_Model_Business_Post_Category();
            $category->deleteCategoryAndDetails($id);

            $this->_redirect('/admin/category');
        } else {
            $this->_redirect('/admin');
        }
    }

}